package com.tencent.hummingbird.portal.mapper;

import com.tencent.hummingbird.portal.pojo.Question;
import com.tencent.hummingbird.portal.pojo.QuestionTag;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
* <p>
    *  Mapper 接口
    * </p>
*
* @author yxb
* @since 2024-01-10
*/
@Repository
public interface QuestionTagMapper extends BaseMapper<QuestionTag> {
    @Select("SELECT q.*\n" +
            "FROM question_tag qt\n" +
            "JOIN question q\n" +
            "ON qt.question_id = q.id\n" +
            "WHERE qt.tag_id = #{tagId} and q.status=0")
    List<Question> selectQuestionsByTagId(Integer tagId);

    @Select(" SELECT * FROM question WHERE STATUS=0 ORDER BY createtime DESC")
    List<Question> selectAll();

    @Delete("delete from question_tag where question_id = #{questionId}")
    Integer deleteByQuestionId(Integer questionId);

    @Select("SELECT * FROM question WHERE title LIKE '%${search}%' OR content LIKE '%${search}%' OR tag_names LIKE '%${search}%'")
    List<Question> searchQuestions(String search);
}
